﻿#region Using

using System.IO;

using Common.Enums;

using GameCommon.ServiceInterfaces;

#endregion

namespace GameCommon.Services
{
    internal class PathService : IPathService
    {
        private const string FontDirectory = @"Content\Fonts\";

        private const string MenuScreenNameSpace = "Menu.Metadata";

        private const string MenuTextureDirectory = @"Content\Menu\";

        private const string MenuXsdNameSpace = "Menu.Metadata.Xsd";

        private const string MiscTextureDirectory = @"Content\Misc\";

        private const string BoardTextureDirectory = @"Content\Board\";

        private const string EffectDirectory = @"Content\Effects\";

        private const string CloudTextureDirectory = @"Content\CloudScreen\";

        private const string HudTextureDirectory = @"Content\Hud\";

        public string GetBoardTexture2D(string name)
        {
            var path = string.Format(@"{0}\{1}.png", BoardTextureDirectory, name);
            CheckExistence(path);
            return path;
        }

        public string GetBoardTexture2D(string name, int zoom)
        {
            var path = string.Format(@"{0}{1}\{2}.png", BoardTextureDirectory, zoom, name);
            CheckExistence(path);
            return path;
        }

        public string GetEffect(string name)
        {
            var path = string.Format("{0}{1}.mgfx", EffectDirectory, name);
            CheckExistence(path);
            return path;
        }

        public string GetCloudTexture2D(string name)
        {
            var path = string.Format("{0}{1}.png", CloudTextureDirectory, name);
            CheckExistence(path);
            return path;
        }

        public string GetHudTexture2D(string name)
        {
            var path = string.Format("{0}{1}.png", HudTextureDirectory, name);
            CheckExistence(path);
            return path;
        }

        public string GetFontFile(FontEnum font, FontSizeEnum size)
        {
            var path = string.Format("{0}{1}_{2}.fnt", FontDirectory, font, (int)size);
            CheckExistence(path);
            return path;
        }

        public string GetFontName(FontEnum font, FontSizeEnum size)
        {
            return string.Format("{0}_{1}", font, size);
        }

        public string GetFontTexture(FontEnum font, FontSizeEnum size)
        {
            var path = string.Format("{0}{1}_{2}_0.png", FontDirectory, font, (int)size);
            CheckExistence(path);
            return path;
        }

        public string GetMenuTexture2D(string name)
        {
            var path = string.Format("{0}{1}.png", MenuTextureDirectory, name);
            CheckExistence(path);
            return path;
        }

        public string GetMenuXml(ScreenEnum screen)
        {
            var path = string.Format("{0}.{1}.xml", MenuScreenNameSpace, screen);

            //// CheckExistence(path);
            return path;
        }

        public string GetMenuXsd(XsdFileEnum xsd)
        {
            var path = string.Format("{0}.{1}.xsd", MenuXsdNameSpace, xsd);

            //// CheckExistence(path);
            return path;
        }

        public string GetMiscTexture2D(string name)
        {
            var path = string.Format("{0}{1}.png", MiscTextureDirectory, name);
            CheckExistence(path);
            return path;
        }

        private static void CheckExistence(string path)
        {
            if (Service.FileService.Exists(path))
            {
                return;
            }

            throw new FileNotFoundException(path);
        }
    }
}